<!--{eval $_TPL['titles'] = array('用户反馈');}-->
<!--{template header_tpl}-->
<script src="<!--{eval echo base_url();}-->resources/js/jquery.validate.min.js" type="text/javascript"></script>
<script src="<!--{eval echo base_url();}-->resources/js/validate.messages_cn.js" type="text/javascript"></script>
<script src="<!--{eval echo base_url();}-->resources/js/validate.additional-methods.min.js" type="text/javascript"></script>
<script src="<!--{eval echo base_url();}-->resources/js/jquery.form.js" type="text/javascript"></script>
    <div class="main_con">
        <div class="left">
			<div id="comments">

				<div id="cmtswitcher">
					<h2>给我们提建议</h2>
					<p>写下您的宝贵意见，我们会尽全力改进。<a href="#msg" >发布评论</a>
				        </p>
				</div>
				<div id="commentlist">
					<!-- msg START -->
					<!--{template msg_list_tpl}-->
					<!-- msg END -->
				</div>
				<form id="msgform" method="post" action="<!--{eval echo base_url()}-->messageboard/add_msg/">
					<div id="respond">
							<div id="author_info">
								<div class="row">
									<input type="text" tabindex="1" size="24" value="{$userinfo[username]}" class="textfield" id="username" name="username">
									<label class="small" for="username">用户名</label>
									<!--{if $userinfo[username]}-->
									<input type="checkbox" tabindex="2"  value="1" id="isanonymous" name="isanonymous" onclick="isAnonymous()">匿名
									<!--{/if}-->
								</div>
								<div class="row">
									<input type="text" tabindex="3" size="24" value="{$userinfo[email]}" class="textfield" id="email" name="email">
									<label class="small" for="email">Email</label>
								</div>
							</div>
						<!-- comment input -->
						<div class="row">
							<textarea cols="65" rows="6" tabindex="4" id="msg" name="msg"></textarea>
							<label class="small" for="msg">&nbsp;</label>
						</div>
						<div id="submitbox">
							<div class="submitbutton">
								<input type="submit" value="提交反馈" tabindex="5" class="button" id="submit" name="submit">
							</div>
							<div class="fixed"></div>
						</div>
					</div>
				</form>
			</div>
			<script type="text/javascript">
			$(document).ready(function() {
				var validator = $("#msgform").validate({
					onfocusout:false,
					errorElement:"span",
					rules: {
						username: {
							required: false,
							rangelength:[1,10] 
						},
						email: {
							required: true,
							email: true
						},
						msg: {
							required: true,
							rangelength:[1,1000]
						}
					},
					messages: {
						username: {
							required: "请输入用户名",
							rangelength: $.validator.format("用户名长度 为{0} 到 {1} 汉字")
						},
						email: {
							required: "请输入邮箱",
							email: "请输入有效邮箱."
						},
						msg: {
							required: "请输入内容",
							rangelength: $.validator.format("用户名长度 为{0} 到 {1} 汉字")
						},
					},
					errorPlacement: function(error, element) {
						element.parent('div').find('label').html(error.html());
					},
					success: function(label) {
					},
					
					submitHandler:function(form) {
						$.post(
							$(form).attr('action'), 
							{ "username": $('#username').val(),
								"email": $('#email').val(),
								'msg': $('#msg').val(),
								'isanonymous': $('#isanonymous').attr('checked') ? 1 : 0
							 },
							 function(result){
								$(form).resetForm();
								$('#username').next('label').html('用户名');
								$('#email').next('label').html('Email');
								if (result.code == 1) {
									getMsgs();
									window.scrollTo(0,0);
								};

							   },
							 "json"
						);
						return false;
					}
				});
			});

			function getMsgs(){
				$.ajax({
				  type: 'POST',
				  url: baseurl+'messageboard/get_msgs',
				  data: {key:'47edbd4fcb4e0ba3c240949542545828'},
				  success: function(result){
						$('#commentlist').html(result);
					},
				  dataType: 'html'
				});
			}
			
			function isAnonymous(){
				if ($('#isanonymous').attr('checked')) {
					$("#username").val('匿名');
				}else{
					$("#username").val("{$userinfo[username]}");
				};
			}
			</script>
        </div>
        <div class="right">
			<!--{template right_side}-->
        </div>
    </div>
<!--{template footer_tpl}-->